package com.cloud.cloudoauth.oauth.controller;

import com.cloud.cloudoauth.oauth.entity.OauthCodeEntity;
import com.cloud.cloudoauth.oauth.service.OauthCodeService;
import com.cloud.cloudoauth.oauth.utils.PageUtils;
import com.cloud.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 
 *
 * @author luoJie
 * @email luoJie@gmail.com
 * @date 2020-09-12 14:45:38
 */
@RestController
@RequestMapping("oauth/oauthcode")
public class OauthCodeController {
    @Autowired
    private OauthCodeService oauthCodeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = oauthCodeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{code}")
    public R info(@PathVariable("code") String code){
		OauthCodeEntity oauthCode = oauthCodeService.getById(code);

        return R.ok().put("oauthCode", oauthCode);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody OauthCodeEntity oauthCode){
		oauthCodeService.save(oauthCode);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OauthCodeEntity oauthCode){
		oauthCodeService.updateById(oauthCode);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] codes){
		oauthCodeService.removeByIds(Arrays.asList(codes));

        return R.ok();
    }

}
